package nz.helloworld;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JToggleButton;

public class TestButtons {

	JFrame frame = new JFrame("Test Buttons");

	JButton jButton = new JButton("JButton");
	JToggleButton jToggleButton = new JToggleButton("Toggle Button");
	JCheckBox jCheckbox = new JCheckBox("Check Box");
	JRadioButton jRadio1 = new JRadioButton("Radio Button 1");
	JRadioButton jRadio2 = new JRadioButton("Radio Button 2");
	JRadioButton jRadio3 = new JRadioButton("Radio Button 3");
	JLabel jLabel = new JLabel("Here is Status, lock here.");

	public TestButtons() {
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container contentPane = frame.getContentPane();
		contentPane.setLayout(new FlowLayout());

		jButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				jLabel.setText("You click JButton");
			}
		});

		jToggleButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent ev) {
				// TODO Auto-generated method stub
				if (jToggleButton.isSelected()) {
					jLabel.setText("You selected Toggle Button");
				} else {
					jLabel.setText("You deselected Toggle Button");
				}
			}
		});

		jCheckbox.addItemListener(new ItemListener() {

			@Override
			public void itemStateChanged(ItemEvent ev) {
				// TODO Auto-generated method stub
				JCheckBox jcb = (JCheckBox) ev.getSource();
				jLabel.setText("Selected Check Box is " + jcb.isSelected());
			}
		});

		ButtonGroup btnGroup = new ButtonGroup();
		ActionListener al = new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent ev) {
				// TODO Auto-generated method stub
				JRadioButton radio = (JRadioButton) ev.getSource();
				jLabel.setText("You selected " + radio.getText());
			}
		};
		jRadio1.addActionListener(al);
		jRadio2.addActionListener(al);
		jRadio3.addActionListener(al);
		btnGroup.add(jRadio1);
		btnGroup.add(jRadio2);
		btnGroup.add(jRadio3);

		contentPane.add(jButton);
		contentPane.add(jToggleButton);
		contentPane.add(jCheckbox);
		contentPane.add(jRadio1);
		contentPane.add(jRadio2);
		contentPane.add(jRadio3);
		contentPane.add(jLabel);

		// frame.pack();
		frame.setSize(200, 250);
	}

	private void show() {
		frame.setVisible(true);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		TestButtons tb = new TestButtons();
		tb.show();
	}

}
